local juemei = fk.CreateSkill{
  name = "mod__juemei",
  frequency = Skill.Compulsory,
}
local U = require "packages/utility/utility"
local juemeiEffects = {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and not player.dead then
      if event == fk.AfterDying then
        return not target.dead
      elseif event == fk.HpChanged then
        return not target:isWounded() and data.num > 0
      else
        return not target:isWounded() and data.num < 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local treasure = Fk:cloneCard("zyg__artofWar")
    if table.contains({Card.Void, Player.Equip}, room:getCardArea(U.prepareDeriveCards(room, {{"zyg__artofWar", Card.Spade, 1}}, "juemei_derivecards")[1]))
    and not player:prohibitUse(treasure) and not player:isProhibited(player, treasure) then
      local id = U.prepareDeriveCards(room, {{"zyg__artofWar", Card.Spade, 1}}, "juemei_derivecards")[1]
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructOutMyEquip, 0)
      local card = Fk:getCardById(id)
      if room:getCardArea(id) ~= Card.Void then
        room:moveCardTo(id, Card.Processing, nil, fk.ReasonDiscard, self.name)
      end
      if not player.dead and not player:prohibitUse(card) and not player:isProhibited(player, card) then
        room:useCard({
          from = player.id,
          tos = {{player.id}},
          card = card,
        })
      else
        room:moveCardTo(id, Card.Void, nil, fk.ReasonJustMove, self.name)
      end
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructOutMyEquip, 1)
    end
    if player:usedSkillTimes(self.name, Player.HistoryGame)%2 == 0 then
      local skilllist = {"mod__jiandai", "mod__fangcan", "mod__juemei"}
      for _, s in ipairs(skilllist) do
        if not Fk.skills[s] then
        elseif player:hasSkill(Fk.skills[s]) then
          room:handleAddLoseSkills(player, "-"..s)
          break
        end
      end
    end
  end
}
juemei:addEffect(fk.HpChanged, juemeiEffects)
juemei:addEffect(fk.MaxHpChanged, juemeiEffects)
juemei:addEffect(fk.AfterDying, juemeiEffects)
Fk:loadTranslationTable{
  ["mod__juemei"] = "绝殙",
  [":mod__juemei"] = "锁定技，当有角色脱离受伤或濒死状态时，你装备【吴起兵法】，若为第偶数次发动，你失去武将牌上首个技能。",
}
return juemei